package com.iwhalecloud.bss.kite.cucc.listener.offer;

import com.iwhalecloud.bss.kite.cucc.event.offer.InitMemOfferEvent;
import com.iwhalecloud.bss.kite.cucc.listener.handler.LocalAdditionalOfferOfOfferHandler;
import com.iwhalecloud.bss.kite.listener.handler.detail.impl.MktHandler;
import com.iwhalecloud.bss.kite.listener.handler.detail.impl.ProdDetailHandler;
import com.iwhalecloud.bss.kite.listener.handler.detail.impl.ProdInstFuncOfOfferHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 *
 * @author liu.zhiyong2
 * @date 2019年6月13日
 * @desc
 */

@Service
public class InitMemOfferListener implements IInitMemOfferListener {

    @Autowired
    private LocalAdditionalOfferOfOfferHandler localAdditionalOfferOfOfferHandler;

    @Autowired
    private ProdDetailHandler prodDetailHandler;

    @Autowired
    private ProdInstFuncOfOfferHandler prodFuncOfOfferHandler;

    @Autowired
    private MktHandler mktHandler;


    /**
     * 明细处理
     * @param event
     */
    @EventListener
    @Order(1)
    @Async
    @Override
    public void registerOfferDetail(InitMemOfferEvent event) {
        String offerId = event.getOfferId();
        String offerInstId = event.getParentInstId();
        String sceneInstId = event.getSceneInstId();
        String custId = event.getCustId();
        String staffId = event.getStaffId();
        boolean offerType = event.isBoleType();
        if (offerType) {
            return;
        }
        prodDetailHandler.init(sceneInstId, offerId, offerInstId, null, custId, staffId, event.getDetailIds());
    }

    /**
     * 功能产品处理
     * @param event
     */
    @EventListener
    @Order(2)
    @Async
    @Override
    public void registerProdFunc(InitMemOfferEvent event) {
        String offerId = event.getOfferId();
        String offerInstId = event.getParentInstId();
        String sceneInstId = event.getSceneInstId();
        String custId = event.getCustId();
        String staffId = event.getStaffId();
        String prodInstId = event.getProdInstId();
        prodFuncOfOfferHandler.init(sceneInstId, offerId, offerInstId, prodInstId, custId, staffId);
    }


    /**
     * 终端处理
     * @param event
     */
    @EventListener
    @Order(3)
    @Async
    @Override
    public void registerMkt(InitMemOfferEvent event) {
        String offerId = event.getOfferId();
        String offerInstId = event.getParentInstId();
        String sceneInstId = event.getSceneInstId();
        String custId = event.getCustId();
        String staffId = event.getStaffId();
        mktHandler.init(sceneInstId, offerId, offerInstId, custId, staffId);
    }
    /**
     * 可选包处理
     * @param event
     */
    @EventListener
    @Order(4)
    @Async
    @Override
    public void registerAdditionalOffer(InitMemOfferEvent event) {
        String offerId = event.getOfferId();
        String offerInstId = event.getParentInstId();
        String sceneInstId = event.getSceneInstId();
        String custId = event.getCustId();
        String staffId = event.getStaffId();
        localAdditionalOfferOfOfferHandler.init(sceneInstId, offerId, offerInstId, custId, staffId);
    }

}
